﻿using Orchard.Data.Migration;
using Orchard.ContentManagement.MetaData;
using Orchard.Core.Contents.Extensions;

namespace Orchard.ExternalAlbum
{
    public class Migrations : DataMigrationImpl
    {
        public int Create()
        {
            SchemaBuilder.CreateTable("PicasaAlbumPartRecord", table => table

                // The following method will create an "Id" column for us and set it is the primary key for the table
                .ContentPartRecord()

                .Column<string>("UserID", column => column.WithLength(255))
                .Column<string>("AlbumID", column => column.WithLength(255))
                .Column<string>("AuthKey", column => column.WithLength(255))
                );

            // Create (or alter) a part called "PicasaAlbumPart" and configure it to be "attachable".
            ContentDefinitionManager.AlterPartDefinition("PicasaAlbumPart", part => part
                .Attachable());

            // Return the version that this feature will be after this method completes
            return 1;
        }


        public int UpdateFrom1()
        {
            // Create a new widget content type with our picasa album part
            ContentDefinitionManager.AlterTypeDefinition("PicasaAlbumWidget", cfg => cfg
                .WithPart("PicasaAlbumPart")
                .WithPart("WidgetPart")
                .WithPart("CommonPart")
                .WithSetting("Stereotype", "Widget"));

            return 2;
        }

    }
}
